Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a LinkedBlockingQueue instead of polling. #44

Merged
merged 1 commit into from
May 15, 2024

Conversation

zainab-ali
Copy link
Contributor

This resolves the busy spin in SBT.

We use a LinkedBlockingQueue and a blocking poll operation to poll every second.

@@ -30,7 +31,7 @@ private[framework] class SbtTask(
loggerPermit.acquire()
try {
while (!finished && !isDone.get()) {
val nextEvent = Option(queue.poll())
val nextEvent = Option(queue.poll(1, TimeUnit.SECONDS))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1 second time is arbitrary.

The loop should terminate when isDone is set, so probably shouldn't poll indefinitely. From reading the code, isDone ought to be set whenever there's an error creating global resources or whenever SBT calls done on the runner. I haven't been able to simulate either of these cases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 1 second is fine.

It's really hard to test a test framework via the SBT interface, so as long as the build still builds, I think your changes are fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with scala-cli and SBT, and it seems to work fine.

You can reproduce the spinlock with

scala-cli test https://gist.github.com/zainab-ali/867fbc095d2ab3ceda498b29bc2b8aba

Here's a screenshot of the CPU usage before:
before

And after (with the current changes):
after

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, that's sufficient to get it merged then 👍

@Baccata Baccata merged commit 0e0ca96 into typelevel:main May 15, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Busy spin in SbtTask results in high CPU usage
2 participants